package com.ai.controller.made;


import com.ai.annotation.EnterPathParamLog;
import com.ai.common.CommonResponse;
import com.ai.entity.function.FunctionPO;
import com.ai.entity.function.FunctionPage;
import com.ai.entity.made.AlgorithmPackageStatus;
import com.ai.entity.made.page.AlgorithmPackagePage;
import com.ai.model.param.AlgorithmPackageParam;
import com.ai.model.param.DeployAlgorithmParam;
import com.ai.service.made.FunctionService;
import com.ai.service.made.IAlgorithmPackageStatusService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 算法管理
 * @author jiaok
 * @since 2024-08-12
 */
@RestController
@RequestMapping("/algorithm-package-status")
public class AlgorithmPackageStatusController {

    @Resource
    private IAlgorithmPackageStatusService iAlgorithmPackageStatusService;

    @Resource
    private FunctionService functionService;


    @ApiOperation("分页查询")
    @PostMapping("list")
    @EnterPathParamLog
    public CommonResponse pageList(@RequestBody FunctionPage page) {
        return  functionService.selectByPage(page);
    }


    @ApiOperation("添加功能")
    @PostMapping("addNewAlarm")
    @EnterPathParamLog
    public CommonResponse addNewAlarm(@RequestBody FunctionPO functionPO) {
        return  functionService.insert(functionPO);
    }

    @ApiOperation("修改功能信息")
    @PostMapping("editAlarm")
    @EnterPathParamLog
    public CommonResponse editAlarm(@RequestBody FunctionPO functionPO) {
        return  functionService.editAlarm(functionPO);
    }



    @ApiOperation("删除功能")
    @PostMapping("delAlarm/{id}")
    @EnterPathParamLog
    public CommonResponse delAlarm(@PathVariable(value = "id") String functionId) {
        return  functionService.delAlarm(functionId);
    }

    @ApiOperation("更新算法信息")
    @PostMapping("updateAlgorithmInfo")
    @EnterPathParamLog
    public CommonResponse updateAlgorithmInfo(@RequestBody AlgorithmPackageStatus AlgorithmPackageStatus) {
        return  iAlgorithmPackageStatusService.updateAlgorithmInfo(AlgorithmPackageStatus);
    }

    @ApiOperation("获取指定算法信息")
    @PostMapping("getAlgorithmInfoById/{id}")
    @EnterPathParamLog
    public CommonResponse getAlgorithmInfoById(@PathVariable(value = "id") String algorithmId) {
        return  iAlgorithmPackageStatusService.getAlgorithmInfoById(algorithmId);
    }


    @PostMapping("/uploadAlgorithm")
    @ApiOperation("上传算法")
    public CommonResponse uploadAlgorithm(@RequestParam("resources") MultipartFile file, @ModelAttribute AlgorithmPackageParam algorithmPackageParam) {

        return iAlgorithmPackageStatusService.uploadAlgorithm(file,algorithmPackageParam);
    }

    @PostMapping("/getServerList")
    @ApiOperation("部署--服务器名称列表")
    @EnterPathParamLog
    public CommonResponse getServerList() {

        return iAlgorithmPackageStatusService.getServerList();
    }

    @PostMapping("/getVersionList/{id}")
    @ApiOperation("部署--获取当前算法拥有的所有版本")
    @EnterPathParamLog
    public CommonResponse getVersionList(@PathVariable(value = "id") String algorithmId) {

        return iAlgorithmPackageStatusService.getVersionList(algorithmId);

    }

    @PostMapping("/deployAlgorithm")
    @ApiOperation("部署到服务器")
    @EnterPathParamLog
    public CommonResponse deployAlgorithm(@RequestBody DeployAlgorithmParam deployAlgorithmParam) {

        return iAlgorithmPackageStatusService.deployAlgorithm(deployAlgorithmParam);

    }

    @PostMapping("/getRevisionHistory")
    @ApiOperation("获取指定算法的所有版本信息")
    @EnterPathParamLog
    public CommonResponse getRevisionHistory(@RequestBody AlgorithmPackagePage algorithmPackagePage) {

        return iAlgorithmPackageStatusService.getRevisionHistory(algorithmPackagePage);

    }



    @PostMapping("/getDeployRelationList/{functionId}")
    @ApiOperation("获取指定算法的部署关系列表")
    @EnterPathParamLog
    public CommonResponse getDeployRelationList(@PathVariable(value = "functionId") String functionId) {

        return iAlgorithmPackageStatusService.getDeployRelationList(functionId);

    }

    @PostMapping("/openAlgorithm/{relationId}")
    @ApiOperation("开启算法")
    @EnterPathParamLog
    public CommonResponse openAlgorithm(@PathVariable(value = "relationId") String relationId) {

        return iAlgorithmPackageStatusService.switchAlgorithm(relationId,"1");

    }

    @PostMapping("/closeAlgorithm/{relationId}")
    @ApiOperation("关闭算法")
    @EnterPathParamLog
    public CommonResponse closeAlgorithm(@PathVariable(value = "relationId") String relationId) {

        return iAlgorithmPackageStatusService.switchAlgorithm(relationId,"2");

    }

    @PostMapping("/getFunctionInfo/{functionId}")
    @ApiOperation("获取功能详细信息")
    @EnterPathParamLog
    public CommonResponse getFunctionInfo(@PathVariable(value = "functionId") String functionId) {

        return iAlgorithmPackageStatusService.getFunctionInfo(functionId);

    }


}
